<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class InitYifanshang extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('yfs_activity', function (Blueprint $table) {
            $table->comment = '一番赏';
            
            $table->increments('id');
            $table->uuid('uuid')->index() ;

            $table->integer('activity_id')->nullable()->index()->comment('活动id');
            // $table->integer('activity_id')->nullable()->index()->comment('活动id');

            $table->string('title', 255)->nullable()->comment('标题'); // 标题
            $table->string('sub_title', 255)->nullable()->comment('副标题'); // 副标题

            $table->string('thumb', 255)->nullable()->comment('封面'); // 封面
            $table->json('images')->nullable()->comment('轮播图');
            $table->json('detail_images')->nullable()->comment('详情图');

            $table->string('image_bg')->nullable()->comment('背景图');
            $table->string('image_3d')->nullable()->comment('3D立体盒子图');

            $table->boolean('is_need_pay')->default(0)->index()->comment('0为免费 1为需要支付'); // none为免费 money为单人民币支付 score为积分支付  money_score

            $table->integer('money_price')->index()->nullable()->comment('人民币价格'); // 支付价格
            $table->integer('score_price')->index()->nullable()->comment('积分价格'); // 支付价格

            $table->integer('visit_total')->default(0)->comment('访问人数'); // 访问人数

            $table->integer('room_total')->comment('房间数量');

            $table->integer('normal_sku_total')->default(0)->comment('普通赏的数量');
            $table->integer('gift_sku_total')->default(0)->comment('赠送赏的数量');

            $table->integer('per_user_limit')->nullable()->comment('每个用户限制参与次数');

            $table->integer('total_per_room')->default(0)->comment('每个房间中的总发数');

            // $table->integer('theme')->default(1)->index()->comment('扭蛋机机柜主题');
            // $table->string('bg_image')->nullable()->comment('背景图');
            // $table->string('image_3d')->nullable()->comment('3D图');

            $table->integer('list_weight')->default(100)->index()->comment('权重');
            $table->tinyInteger('status')->index()->default(1)->nullable()->comment('0已下架 1为已上架');


            $table->softDeletes();
            $table->timestamps();
        });

        Schema::create('yfs_skus', function (Blueprint $table) {
            $table->comment = '一番赏sku表';

            $table->increments('id');
            $table->uuid('uuid')->index();

            $table->integer('activity_id')->index()->nullable()->comment('活动id');

            $table->tinyInteger('sku_type')->default(1)->comment('奖品类型, 1为自定义实物，2为绑定商城商品 3为平台虚拟资产  4为无任何奖品');

            $table->json('assets')->nullable()->comment('当sku_type为2时，绑定的虚拟资产'); 
            $table->integer('product_id')->index()->nullable()->comment('当sku_type为1时, 绑定的商品id');

            $table->string('title', 100)->nullable()->comment('标题'); // 标题
            $table->string('number', 255)->nullable()->comment('编号'); // 副标题
            $table->string('thumb', 255)->nullable()->comment('封面'); // 副标题

            $table->string('shang_title', 20)->nullable()->comment('赏类型文字'); // 赏类型文字
            $table->tinyInteger('shang_type')->default(0)->index()->comment('0为普通赏 1为购买赏');

            $table->integer('money_price')->unsigned()->nullable()->comment('人民币价格');     // 价格
            $table->integer('score_price')->unsigned()->nullable()->comment('积分价格');     // 价格

            $table->integer('stock')->default(0)->comment('奖品库存'); // 销量
            $table->integer('sales')->default(0)->comment('奖品销量'); // 销量

            $table->float('odds')->nullable()->comment('中奖几率, 30表示30%');

            $table->json('target_phones')->nullable();

            $table->integer('lottery_start_point')->nullable()->comment('抽奖开始位置(包含)');
            $table->integer('lottery_end_point')->nullable()->comment('抽奖结束位置(包含)');

            $table->integer('total_per_room')->default(0)->comment('每个房间中的数量');

            $table->integer('list_weight')->default(100)->index()->comment('权重');
            $table->tinyInteger('status')->index()->default(1)->nullable()->comment('0已下架 1为已上架');

            $table->softDeletes();
            $table->timestamps();
        });

        Schema::create('yfs_rooms', function (Blueprint $table) {
            $table->comment = '一番赏房间表';

            $table->increments('id');
            $table->uuid('uuid')->index() ;

            $table->integer('activity_id')->index()->nullable()->comment('活动id');
            $table->integer('number')->nullable()->comment('房间编号');

            $table->integer('num')->nullable()->comment('第几箱');

            $table->integer('stock')->default(0)->comment('房间库存');
            $table->integer('sales')->default(0)->comment('房间销量');

            $table->integer('open_index')->default(0)->comment('抽出的次数，1为第一次');

            $table->json('open_records')->nullable()->comment('抽出记录');
            $table->json('sku_options')->nullable()->comment('房间内sku销量和库存');

            $table->softDeletes();
            $table->timestamps();
        });

        // Schema::create('yfs_room_skus', function (Blueprint $table) {
        //     $table->comment = '一番赏房间sku表';

        //     $table->increments('id');
        //     $table->uuid('uuid')->index() ;

        //     $table->integer('stock')->nullable()->comment('库存');
        //     $table->integer('cached_stock')->nullable()->comment('冻结的库存');
        //     $table->integer('sales')->nullable()->comment('销量');

        //     $table->softDeletes();
        //     $table->timestamps();
        // });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::disableForeignKeyConstraints();
        Schema::dropIfExists('yfs_activity');
        Schema::dropIfExists('yfs_skus');
        Schema::dropIfExists('yfs_rooms');
    }
}
